/*
based on an article at link "http://reignwaterdesigns.com/ad/tidbits/rateme/"
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var compreSet; // Is the PreSet value onces a selection has been made
var colpreSet;
var exppreSet;
var com;
var col;
var exp;
var comvalid="no";
var colvalid="no";
var expvalid="no";
var result = new Array();
result[0]="";
result[1]="";
result[2]="";

// Rollover for image Stars //
function rating(rated,id,num){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	
	if(!rated){
		s = num.id.replace(id+"_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById(id+"_"+i).className = "on";
				document.getElementById(id+"rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById(id+"_"+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(rated,id,me){
	
	if (id=="com") {
		preSet=compreSet
	}
	else if (id=="col") {
		preSet=colpreSet;
	}
	else if (id=="exp") {
		preSet=exppreSet;
	}
	
	
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById(id+"_"+i).className = "";
				document.getElementById(id+"rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			rating(rated,id,preSet);
			//document.getElementById(id+"rateStatus").innerHTML = document.getElementById(id+"ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(rated,id,me){
	if(!rated){
		if (id=='com') {
			comvalid="ok";
			comrated=1;
			compreSet = me;
			rating(comrated,id,me);
		}
		else if (id=="col") {
			colvalid="ok";
			colrated=1;
			colpreSet = me;
			rating(colrated,id,me);
		}
		else if (id=="exp") {
			expvalid="ok";
			exprated=1;
			exppreSet = me;
			rating(exprated,id,me);
		}
		document.getElementById(id+"rateStatus").innerHTML = me.title;
		//rated=1;
		sendRate(id,me);
		//rating(rated,id,me);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(id,sel){
	//alert("Your rating was: "+sel.title);
	if (id=="com") {
		result[0] = sel.title;
	}
	else if (id=="col") {
		result[1] = sel.title;
	}
	else if (id=="exp") {
		result[2] = sel.title;
	}
	document.input.com.value=result[0];
	document.input.col.value=result[1];
	document.input.exp.value=result[2];
}

function communication(sel) {
	return sel.title
}

function valid() {
	alert("result:"+result[0])
	
}